#include "SubManager.h"
#include <cassert>
#include <iostream>
#include <algorithm>

using namespace std;

SubManager::SubManager(){}

void SubManager::tick(){}

    //Draw all static entities at their correct positions on the Bitmap
void SubManager::drawAll(BITMAP *pScreen) {
    list<Entity *>::iterator ei;
    
    for(ei = mEntities.begin(); ei != mEntities.end(); ei++) {
        //blit(): *bmp source, *bmp dest, sourcex,y,destx,y,W,H
        Rect *pos = (*ei)->getPos();
        draw_sprite(
           pScreen,
           (*ei)->getGraphic(),
           pos->posX,
           pos->posY
        );
    }

}

void SubManager::addEntity(Entity *pEntity) {
    assert(pEntity != NULL);
    mEntities.push_back(pEntity);
}

void SubManager::removeEntity(Entity *pEntity) {
    assert(pEntity != NULL);
    list<Entity*>::iterator it = 
        find(mEntities.begin(), mEntities.end(), pEntity);
    
    /* TODO: Remove printouts later */
    if(it != mEntities.end()) {
        cout << "removing Entity from SubManager" << endl;
        mEntities.erase(it);
    }
    else
        cout << "Could not find entity in list" << endl;
        

}

int SubManager::getCount() {
    return mEntities.size();
}
